import {defineStore} from 'pinia'
import {ref} from 'vue'
import axios from 'axios'

// 命名规范 use+仓库唯一标识+store
export const useChannelStore = defineStore('channel', () => {
  // 定义数据
  const channelList = ref([])

  // 定义方法
  const getChannelList = async () => {
    const {data: {data}} = await axios.get('http://geek.itheima.net/v1_0/channels')
    const channels = data.channels
    channelList.value = channels
  }

  // 定义getters

  // 将数据，方法和定义的getters返回
  return {
    channelList,
    getChannelList
  }
})
